
package com.updesignsz.api.controller;

import com.updesignsz.api.service.ArticleService;
import com.updesignsz.api.util.ResponseUtil;
import com.updesignsz.commom.util.ResultVo;
import net.sf.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 文章
 * Creation date 2020-8-8 15:06:04
 */
@RestController
@RequestMapping(value = "/api/article", method = RequestMethod.POST)
public class ArticleController {

	@Autowired
	private ArticleService articleService;

    /**
     * 文章列表
     */
    @RequestMapping(value = "/list")
    public void list(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ResultVo vo = new ResultVo();
        try {
            JSONObject json = ResponseUtil.getRequestAsJSONObject(request);
            if (!json.containsKey("id")) {
                json.put("type", 2);
            }
            vo.setData(articleService.findAll(json));
        } catch (Exception e) {
            e.printStackTrace();
        }
        ResponseUtil.outJson(vo.toJsonMsg(), response);
    }


    /**
     * 文章列表
     */
    @RequestMapping(value = "/about")
    public void about(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ResultVo vo = new ResultVo();
        try {
            JSONObject json = ResponseUtil.getRequestAsJSONObject(request);
            json.put("type", 1);
            vo.setData(articleService.findAll(json));
        } catch (Exception e) {
            e.printStackTrace();
        }
        ResponseUtil.outJson(vo.toJsonMsg(), response);
    }


    /**
     * 文章列表
     */
    @RequestMapping(value = "/contact")
    public void contact(HttpServletRequest request, HttpServletResponse response) throws Exception {
        ResultVo vo = new ResultVo();
        try {
            JSONObject json = ResponseUtil.getRequestAsJSONObject(request);
            json.put("type", 3);
            vo.setData(articleService.findAll(json));
        } catch (Exception e) {
            e.printStackTrace();
        }
        ResponseUtil.outJson(vo.toJsonMsg(), response);
    }
}